package com.cgc.web.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.cgc.entity.Emp;
import com.cgc.service.EmpService;
import com.cgc.utils.ReturnJson;

public class LoginAction extends BaseAction<Emp>{
	
	private String username;
	
	private String pwd;
	
	public EmpService empService;
	
	/**
	 * 登 录
	 */
	public void checkUser(){
		Emp loginUser =empService.checkUser(username, pwd);
		Map<String, Object> rtn = new HashMap<String, Object>();
		if(loginUser!=null){
			//存session
			this.getRequest().getSession().setAttribute("loginUser", loginUser);
			rtn.put("success", true);
			rtn.put("message", "登 录成功");
		}else{
			rtn.put("success", false);
			rtn.put("message", "登 录失败，请输入正确的用户名和密码");
		}
		ReturnJson.writejson(JSON.toJSONString(rtn), getResponse());
	}

	
	public void showName(){
		Map<String, Object> rtn = new HashMap<String, Object>();
		Emp emp = (Emp) getRequest().getSession().getAttribute("loginUser");
		if(null!=emp){
			rtn.put("username", emp.getUsername());
			rtn.put("success", true);
			rtn.put("message", "用户在线");
		}else{
			rtn.put("success", false);
			rtn.put("message", "非法登 录");
		}
		ReturnJson.writejson(JSON.toJSONString(rtn), getResponse());
	}
	
	
	public EmpService getEmpService() {
		return empService;
	}



    @Autowired
	public void setEmpService(EmpService empService) {
		this.empService = empService;
		super.setBaseService(this.empService);
	}




	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	
	

}
